package com.example.getfromservice.DB;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;


public class MySQLiteHelper extends SQLiteOpenHelper {

	  private static final String DATABASE_NAME = "srviceDB.db";
	  private static final int DATABASE_VERSION = 3;
	  
	  public static final String TABLE_CATEGORY = "Categories";
	  
	  public static final String CAT_COLUMN_ID = "Id";
	  public static final String CAT_DESCRIBE_ID = " integer primary key autoincrement";
	 
	  public static final String CAT_COLUMN_CAT_ID = "Category_id";
	  public static final String CAT_DESCRIBE_CAT_ID = " integer  not null";
	 
	  public static final String CAT_COLUMN_NAME = "Name";
	  public static final String CAT_DESCRIBE_NAME = " text not null";
	  
	  public static final String CAT_COLUMN_CHANGES = "Changes";
	  public static final String CAT_DESCRIBE_CHANGES  = " integer not null";
	 
	  
	  public static final String TABLE_BOOK = "Books";
	  
	  public static final String BOOK_COLUMN_ID = "Id";
	  public static final String BOOK_DESCRIBE_ID = " integer primary key autoincrement";
	 
	  public static final String BOOK_COLUMN_CAT_ID = "Category_id";
	  public static final String BOOK_DESCRIBE_CAT_ID = " integer not null";
	  
	  public static final String BOOK_COLUMN_BOOK_ID = "Book_id";
	  public static final String BOOK_DESCRIBE_BOOK_ID = " integer not null";
	 
	  public static final String BOOK_COLUMN_ISBN = "ISBN";
	  public static final String BOOK_DESCRIBE_ISBN = " text not null";
	  
	  public static final String BOOK_COLUMN_TITLE = "Title";
	  public static final String BOOK_DESCRIBE_TITLE = " text not null";
	  
	  public static final String BOOK_COLUMN_AUTHOR = "Author";
	  public static final String BOOK_DESCRIBE_AUTHOR = " text not null";
	  
	  public static final String BOOK_COLUMN_CHANGES = "Changes";
	  public static final String BOOK_DESCRIBE_CHANGES  = " integer not null";
	 
	  
	  // Database creation statement
	  private static final String DATABASE_CREATE_CAT = "create table "  
	  + TABLE_CATEGORY + "(" + CAT_COLUMN_ID + CAT_DESCRIBE_ID +","+ CAT_COLUMN_CAT_ID + CAT_DESCRIBE_CAT_ID +","+ CAT_COLUMN_NAME + CAT_DESCRIBE_NAME + ","+ CAT_COLUMN_CHANGES + CAT_DESCRIBE_CHANGES +");";
	  
	  private static final String DATABASE_CREATE_BOOK = "create table "  
			  + TABLE_BOOK + "(" + BOOK_COLUMN_ID + BOOK_DESCRIBE_ID +","+ BOOK_COLUMN_CAT_ID + BOOK_DESCRIBE_CAT_ID +","+ BOOK_COLUMN_BOOK_ID + BOOK_DESCRIBE_BOOK_ID + ","+ BOOK_COLUMN_ISBN + BOOK_DESCRIBE_ISBN +","+ BOOK_COLUMN_TITLE + BOOK_DESCRIBE_TITLE +","+ BOOK_COLUMN_AUTHOR + BOOK_DESCRIBE_AUTHOR +","+ BOOK_COLUMN_CHANGES + BOOK_DESCRIBE_CHANGES +");";
			  


	  public MySQLiteHelper(Context context) {
	    super(context, DATABASE_NAME, null, DATABASE_VERSION);
	  }

	  @Override
	  public void onCreate(SQLiteDatabase database) {
	    database.execSQL(DATABASE_CREATE_CAT);
	    database.execSQL(DATABASE_CREATE_BOOK);
	  }

	  @Override
	  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	    Log.w(MySQLiteHelper.class.getName(),
	        "Upgrading database from version " + oldVersion + " to "
	            + newVersion + ", which will destroy all old data");
	    db.execSQL("DROP TABLE IF EXISTS " + TABLE_CATEGORY);
	    db.execSQL("DROP TABLE IF EXISTS " + TABLE_BOOK);
	    onCreate(db);
	  } 
	  
	
	  

}
